"""
@Time    : 2025/7/22 10:40
@Author  : white.tie
@File    : 流媒体.py
@Desc    : 
"""
import uvicorn
from fastapi import FastAPI
from fastapi.responses import StreamingResponse

app = FastAPI()

async def fake_video_streamer():
    for i in range(10):
        yield b"some fake video bytes"

@app.get("/")
async def main():
    return StreamingResponse(fake_video_streamer())



some_file_path = "video/test.mp4"
app = FastAPI()

@app.get("/test.mp4")
def main():
    print("-----")
    def iterfile():  # (1)
        with open(some_file_path, mode="rb") as file_like:  # (2)
            yield from file_like  # (3)

    return StreamingResponse(iterfile(), media_type="video/mp4")

if __name__ == '__main__':
    uvicorn.run(app)
